/*
 * Copyright (c) 2023 Cshoo Org. All Rights Reserved.
 */

package org.cshoo.tattoo.authorize.app;

import lombok.extern.slf4j.Slf4j;
import org.cshoo.tattoo.authorize.api.dto.AddButtonReq;
import org.cshoo.tattoo.authorize.api.dto.UpdateButtonReq;
import org.cshoo.tattoo.authorize.domain.po.Button;
import org.cshoo.tattoo.authorize.domain.service.ButtonService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 杨翼
 * @since 1.0
 */
@Service
@Slf4j
public class ButtonAppService {

    @Resource
    private ButtonService buttonService;

    /**
     * 判断菜单编号是否存在
     *
     * @return 判断按钮编号是否存在
     */
    public boolean buttonCodeExists(String code, Long menuId) {
        return buttonService.buttonCodeExists(code, menuId);
    }

    /**
     * 添加一个button
     *
     * @param addButtonReq 添加按钮请求
     */
    public void addButton(AddButtonReq addButtonReq) {
        Button button = new Button();
        BeanUtils.copyProperties(addButtonReq, button);
        buttonService.addButton(button);
    }

    /**
     * 修改一个button
     *
     * @param updateButtonReq 修改button请求
     */
    public void updateButton(UpdateButtonReq updateButtonReq) {
        Button button = new Button();
        BeanUtils.copyProperties(updateButtonReq, button);
        buttonService.updateButton(button);
    }

    /**
     * 删除一个button
     *
     * @param id button id
     */
    public void deleteButton(Long id) {
        buttonService.deleteButton(id);
    }

    /**
     * 根据菜单查询button，即查询这个菜单下的buttons
     *
     * @param menuId 菜单id
     * @return buttons
     */
    public List<Button> findButtonsByMenu(Long menuId) {
        return buttonService.findButtonsByMenuId(menuId);
    }

    /**
     * 根据角色id查询按钮
     *
     * @param roleId 角色id
     * @return 按钮
     */
    public List<Button> findByRoleId(Long roleId) {
        return buttonService.findByRoleId(roleId);
    }
}
